package com.etc.dao;

import com.etc.entity.User;
import com.etc.utils.DruidUtils;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.security.UnrecoverableKeyException;
import java.sql.*;

/**
 * @Author kalista
 * @Description 操作数据库
 * @Date 2020/12/11  11:23
 **/
public class UserDao {



    /**
     * 根据用户名和密码得到用户
     *
     * @param username
     * @param
     * @return
     */
    public User login(String username) {
        User user = null;
        // 获取连接
        String sql = "select * from user where name = ?";
        try {
            PreparedStatement ps = DruidUtils.getConnection().prepareStatement(sql);
            ps.setString(1, username);
            ResultSet resultSet = ps.executeQuery();
            while (resultSet.next()) {
                user = new User();
                user.setId(resultSet.getInt("id"));
                user.setPassword(resultSet.getString("name"));
                user.setUsername(resultSet.getString("age"));
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return user;
    }


}
